package com.sgb.knowledgeshare.view.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.knowledgeshare.BR;
import com.sgb.knowledgeshare.R;
import com.sgb.knowledgeshare.entity.ReceiveLaudEntity;
import com.sgb.knowledgeshare.view.activity.ShareUserActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;
import java.util.List;

/**
 * Created by fq on 2020/9/24 0024
 * Description：
 */
public class MagessLandAdapter extends BaseRecycleAdapter<ReceiveLaudEntity.RecordsBean> {

    public MagessLandAdapter(Context context, List<ReceiveLaudEntity.RecordsBean> datas) {
        super(context, R.layout.item_magess_land, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, ReceiveLaudEntity.RecordsBean recordsBean) {
        holder.setBinding(BR.viewModel, recordsBean);
        ImageView landlogos = holder.itemView.findViewById(R.id.land_logo);
        TextView landnames = holder.itemView.findViewById(R.id.land_name);
        TextView landtimes = holder.itemView.findViewById(R.id.land_time);
        TextView landContent = holder.itemView.findViewById(R.id.land_content);
        ImageView landimvs = holder.itemView.findViewById(R.id.land_imv);
        Glide.with(context).load(recordsBean.getPhoto())
                .apply(RequestOptions.bitmapTransform(new CircleCrop()).placeholder(R.mipmap.share_def_photo))
                .into(landlogos);
        RequestOptions options = new RequestOptions()
                .bitmapTransform(new RoundedCorners(3)).override(300,300)
                .placeholder(R.mipmap.share_classify_loading)//图片加载出来前，显示的图片
                .fallback( R.mipmap.share_classify_failure) //url为空的时候,显示的图片
                .error(R.mipmap.share_classify_failure);//图片加载失败后，显示的图片
        Glide.with(context).load(recordsBean.getCover()).apply(options).into(landimvs);
        landnames.setText(recordsBean.getName()+"");
        if (recordsBean.getType()==2){
            landContent.setText("赞了你的评论");
        }else {
            landContent.setText("赞了你的作品");
        }
        landtimes.setText(DateUtils.getDayUtils(Long.parseLong(recordsBean.getLaudTime())));
        landlogos.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareUserActivity.start(context, recordsBean.getUserNo());
            }
        });
    }
}
